<template>
  <card title="错题集" signText="注：目前仅收集客观题" :width="1120">
    <div class="search">
      <div class="search_item">
        <div class="label">课程名称</div>
        <el-input size="small" class="ipt_item" v-model="form.courseName" clearable placeholder="请输入课程名称"></el-input>
      </div>
      <div class="search_item">
        <div class="label">学期</div>
        <el-select size="small" class="ipt_item" v-model="form.semesterId" clearable placeholder="请选择学期">
          <el-option label="全部" value=""/>
          <el-option
            v-for="item in semesterList"
            :key="item.semesterId"
            :label="item.semesterName"
            :value="item.semesterId"
          >
          </el-option>
        </el-select>
      </div>
      <div>
        <el-button size="small" type="primary" @click="getMistakeList">搜索</el-button>
        <el-button size="small" @click="resetQuery">重置</el-button>
      </div>
    </div>
    <div v-loading="loading">
      <courses
        :isLink="true"
        :list="mistakeList"
        type="wrongQuestions"
        height="calc(100vh - 68px - 18px - 190px)"
      ></courses>
    </div>
  </card>
</template>

<script>
import { semesterList } from '@/api/mine/mine'
import courses from '@/components/courses'
import { getMistakeListApi } from '@/api/ExaminationModule/wrongQuestion'

export default {
  name: 'wrongSetOfQuestions',
  components: {
    courses
  },
  data() {
    return {
      loading: false,
      semesterList: [],
      mistakeList: [],
      form: {
        pageNum: 1,
        pageSize: 999999,
        semesterId: '',
        courseName: ''
      }
    }
  },
  created() {
    this.getSemesterList()
    this.getMistakeList()
  },
  methods: {
    /* 获取学期列表 */
    async getSemesterList() {
      let res = await semesterList()
      this.semesterList = res.data
      this.form.semesterId = this.$store.getters.schoolInfo.semesterId
    },
    resetQuery() {
      this.form = {
        pageNum: 1,
        pageSize: 999999,
        semesterId: '',
        courseName: ''
      }
      this.getMistakeList()
    },
    async getMistakeList() {
      this.loading = true
      try {
        let params = {
          ...this.form
        }
        let res = await getMistakeListApi(params)
        const { code, data } = res
        if (code === 200) {
          this.mistakeList = data.rows
        }
      } catch (e) {
        console.error(e)
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style scoped lang="scss">
.search {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 20px 20px 10px;
  box-sizing: border-box;
  gap: 0 24px;

  .search_item {
    display: flex;
    align-items: center;
    gap: 0 16px;

    .label {
      font-family: PingFangSC, PingFang SC, sans-serif;
      font-weight: 400;
      font-size: 14px;
      color: #666666;
    }

    .ipt_item {
      width: 220px;
    }
  }

  .search_item:nth-child(2) {
    margin-left: 32px;
  }
}
</style>
